// mircoApp/integralShift/integralShiftIndex/integralShiftIndex.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: app.globalData.imgPath,
    page_list: [],
    otherParams: [],
    active: 0,
    info: [],
    pageTitle: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData();
  },
  tabsChange(e) {
    this.setData({
      active: e.detail.index
    })
    this.getRecord(this.data.page_list[this.data.active].id);
  },
  onClickLeft() {
    wx.navigateBack({
      delta: 1
    })
  },
  toUrl() {
    wx.navigateTo({
      url: this.data.otherParams.jump_url,
    })
  },
  toRecord() {
    wx.navigateTo({
      url: '/mircoApp/integralShift/integralShiftRecord/integralShiftRecord?pool_id=' + this.data.page_list[this.data.active].id
    })
  },
  getRecord(id) {
    let urlStr = app.getNetAddresss("plugin.integral-shift.frontend.modules.detail.controllers.page.index");
    app._getNetWork({
      url: urlStr,
      data: {
        pool_id: id ? id : ''
      },
      success: (resdata) => {
        let res = resdata.data
        if (res.result == 1) {
          this.setData({
            lock_name: res.data.otherParams.lock_name,
            integral_name: res.data.otherParams.integral_name,
            info: res.data,
          })
        } else {
          app.tips(res.msg)
        }
      },
      fail: function (res) {}
    });
  },
  getData() {
    let urlStr = app.getNetAddresss("plugin.integral-shift.frontend.modules.pool.controllers.list.index");
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        let res = resdata.data
        if (res.result == 1) {
          console.log(res.data)
          this.setData({
            page_list: res.data.page_list,
            otherParams: res.data.otherParams,
            pageTitle: `${res.data.otherParams.plugin_name}`,
          })
          this.getRecord(this.data.page_list[this.data.active].id)
          wx.setNavigationBarTitle({
            title: "",
          })
        } else {
          app.tips(res.msg)
        }
      },
      fail: function (res) {}
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})